<template>
    <div class="r_main">
        <div class="outer">
            <div class="y1">
                <div class="list " v-for="item in list" :key="item.id" @click="goPage('/columnIndex', id)">
                    <span class="line1">
                        {{ item.title }}
                    </span>
                </div>

            </div>

        </div>
        <el-empty style="margin: 0 auto;" description="没有内容了" v-if="list.length == 0"></el-empty>

    </div>

</template>
<script>
export default {

    data() {
        return {
            list: [],
            dialogVisible: false,
            form: { type: '' },
            pageNum: 1,
            totalPage: 1,
            loading: false,
            new_id: 0
        }
    },
    props: {
        id: {
            type: Number || String,
            default: 0,
        }
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    mounted() {
        let id = this.$route.query.id
        if (id) {
            console.log('请求一次')
            this.new_id = id
            this.pageNum = 1
            this.getList()
        }
        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },
    watch: {
        id(n) {
            if (n) {
                console.log('请求监听')

                this.pageNum = 1,
                    this.getList()
            }
        }
    },
    methods: {
        goPage(url, id) {
            this.$router.push({
                path: url,
                query: {
                    id
                }
            })
        },
        // 目录
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
                id: this.id != 0 ? this.id : this.new_id
            }
            this.$api.getVipChapter(params).then(res => {
                if (res.data.code == 1) {
                    this.list = []
                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },

        getTabtype(t) {
            this.curType = t
        },
        load() {
            console.log("处理触底");
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        onsubmit() {
            console.log(this.form);

        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                // this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.r_main {
    width: 100%;
}


.outer {
    display: flex;
    align-items: flex-start;
    padding-bottom: 20px;

    .y1 {
        width: 100%;
        display: flex;
        flex-wrap: wrap;

        .list {
            width: calc(50% - 27.5px);
            border-bottom: 1px dashed #E5E5E5;
            padding: 15px 0;
            font-size: 18px;
            color: #757474;

            &:nth-child(2n) {
                margin-left: 55px;
            }

            &:hover {
                background-color: #E8F2FE;
            }

            span {
                display: inline-block;
                width: 500px;
            }
        }
    }


}
@media screen and (max-width:768px) {
    .outer .y1 .list{
        font-size: 14px;
        padding: 8px 10px;
        display: flex;
        align-items: center;
    }
}
</style>